package com.admin.dbdao;

import com.data.bean.Menu;
import com.data.dbdao.BaseDao;
import com.data.util.FinalStringUtils;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 软件分类管理数据层
 *
 * @author:HingLo
 * @create 2017-08-29 9:52
 **/
@Repository
@Transactional
public class SoftWareClassifyDao extends BaseDao {
    public boolean saveSoftWareClassDao(Menu menu) {
        return super.saveMassageDao(menu);
    }

    /**
     * 查询一级菜单
     * 默认查询软件的一级菜单信息
     *
     * @return
     */
    public List<?> findMenuOneDao() {
        String hql = "from Menu where fid=? and type=?";
        return super.findMassageDao(hql, String.valueOf(FinalStringUtils.SOFTTYPE), FinalStringUtils.SOFTTYPE);
    }

    /**
     * 查询一级菜单,一级菜单的父类id与类型相同，是0，或者1
     *
     * @return
     */
    public List<?> findMenuOneDao(int type) {
        String hql = "select id,name from Menu where fid=? and type=?";
        return super.findMassageDao(hql, String.valueOf(type), type);
    }

    /**
     * 查看全部分类
     *
     * @return
     */
    public List<?> lookClassDao() {

        String hql = "select id,fid,name from Menu ";
        return super.findMassageDao(hql);
    }

    /**
     * 根据id返回相关类别信息
     *
     * @param param
     * @return
     */
    public Menu lookOneClassDao(String param) {
        String hql = "from Menu where id=?";
        List<Menu> list = (List<Menu>) super.findMassageDao(hql, param);
        return list.size() > 0 ? list.get(0) : null;
    }

    /**
     * 更新了类别名称
     *
     * @param id
     * @param name
     * @return
     */
    public boolean changeClassDao(String id, String name) {
        String hql = "update Menu set name=? where id=?";
        return super.updateOneMssageDao(hql, name, id);
    }

    /**
     * 根据父类id,与菜单类型（软件或者游戏）来查找二级菜单
     *
     * @param fid
     * @param type
     * @return
     */
    public List<?> findMenuTwoDao(String fid, int type) {
        String hql = "select id,name from Menu where fid=? and type=?";
        return super.findMassageDao(hql, fid, type);
    }
}
